package cc.laop.netty.server;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import io.netty.channel.socket.SocketChannel;

public class ChannelManager {

	private static Map<String, SocketChannel> channelMap = new ConcurrentHashMap<>();

	public static void add(String channelid, SocketChannel channel) {
		channelMap.put(channelid, channel);
	}

	public static void remove(String channelid) {
		channelMap.remove(channelid);
	}

	public static SocketChannel get(String channelid) {
		return channelMap.get(channelid);
	}

	public static void remove(SocketChannel channel) {
		for (Map.Entry<String, SocketChannel> entity : channelMap.entrySet()) {
			if (entity.getValue() == channel) {
				channelMap.remove(entity.getKey());
			}
		}
	}

	public static Map<String, SocketChannel> getChannelMap() {
		return channelMap;
	}

}
